Overview

Welcome to the ggplot2 graph gallery! This Quarto website contains a series of graphs composed in ggplot2. Install ggplot2 using the code below:

View code
install.packages("ggplot2")
library(ggplot2)

Or install ggplot2 as part of the tidyverse:

View code
install.packages("tidyverse")
library(tidyverse)

Data

An effort has been made to keep the number of additional packages at a minimum, so most of the graphs have been created with one of two datasets:

penguins

Artwork by @allison_horst

The majority of the graphs are built using the palmerpenguins::penguins data.

View code
install.packages("palmerpenguins")
library(palmerpenguins)
palmerpenguins::penguins |> glimpse()
Rows: 344
Columns: 8
$ species           <fct> Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…
$ island            <fct> Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…
$ bill_length_mm    <dbl> 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …
$ bill_depth_mm     <dbl> 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …
$ flipper_length_mm <int> 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…
$ body_mass_g       <int> 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …
$ sex               <fct> male, female, female, NA, female, male, female, male…
$ year              <int> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…

movies

Some of the graphs are built using the ggplot2movies::movies data.

View code
install.packages("ggplot2movies")
library(ggplot2movies)
ggplot2movies::movies |> glimpse()
Rows: 58,788
Columns: 24
$ title       <chr> "$", "$1000 a Touchdown", "$21 a Day Once a Month", "$40,0…
$ year        <int> 1971, 1939, 1941, 1996, 1975, 2000, 2002, 2002, 1987, 1917…
$ length      <int> 121, 71, 7, 70, 71, 91, 93, 25, 97, 61, 99, 96, 10, 10, 10…
$ budget      <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
$ rating      <dbl> 6.4, 6.0, 8.2, 8.2, 3.4, 4.3, 5.3, 6.7, 6.6, 6.0, 5.4, 5.9…
$ votes       <int> 348, 20, 5, 6, 17, 45, 200, 24, 18, 51, 23, 53, 44, 11, 12…
$ r1          <dbl> 4.5, 0.0, 0.0, 14.5, 24.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4…
$ r2          <dbl> 4.5, 14.5, 0.0, 0.0, 4.5, 4.5, 0.0, 4.5, 4.5, 0.0, 0.0, 0.…
$ r3          <dbl> 4.5, 4.5, 0.0, 0.0, 0.0, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5…
$ r4          <dbl> 4.5, 24.5, 0.0, 0.0, 14.5, 14.5, 4.5, 4.5, 0.0, 4.5, 14.5,…
$ r5          <dbl> 14.5, 14.5, 0.0, 0.0, 14.5, 14.5, 24.5, 4.5, 0.0, 4.5, 24.…
$ r6          <dbl> 24.5, 14.5, 24.5, 0.0, 4.5, 14.5, 24.5, 14.5, 0.0, 44.5, 4…
$ r7          <dbl> 24.5, 14.5, 0.0, 0.0, 0.0, 4.5, 14.5, 14.5, 34.5, 14.5, 24…
$ r8          <dbl> 14.5, 4.5, 44.5, 0.0, 0.0, 4.5, 4.5, 14.5, 14.5, 4.5, 4.5,…
$ r9          <dbl> 4.5, 4.5, 24.5, 34.5, 0.0, 14.5, 4.5, 4.5, 4.5, 4.5, 14.5,…
$ r10         <dbl> 4.5, 14.5, 24.5, 45.5, 24.5, 14.5, 14.5, 14.5, 24.5, 4.5, …
$ mpaa        <chr> "", "", "", "", "", "", "R", "", "", "", "", "", "", "", "…
$ Action      <int> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0…
$ Animation   <int> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1…
$ Comedy      <int> 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1…
$ Drama       <int> 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0…
$ Documentary <int> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0…
$ Romance     <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ Short       <int> 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1…

Additional datasets

A few of the graphs using datasets from the fivethirtyeight package.

To view a table of available datasets in the fivethirtyeight package, view the Data Frame Name and Article Title columns in the datasets_master table.

View code
install.packages("fivethirtyeight")
library(fivethirtyeight)
fivethirtyeight::datasets_master |> 
    select(`Data Frame Name`, `Article Title`)

Graph Packages

Most of the graphs in this gallery can be built using on of ggplot2 ’s many geom_* functions. If a graph requires additional geoms or functions, the development version for these packages have been listed.

Univariate Graphs

The following graphs are used to display single variable distributions:

  • Bar Graphs

  • Histograms

  • Frequency Polygons

  • Dot-Plots

  • Density Plots

  • Violin Plots

  • Box-Plots

Comparing Amounts

The following graphs are used to display amounts:

  • Grouped column-graphs

  • Summarized column-graphs

  • Overlapping bar-graphs

  • Side-to-side ("dodge") bar-graphs

  • Side-to-side ("dodge2") bar-graphs

  • Waffle charts

    • ggwaffle package

      View code
      # Waffle Charts
      devtools::install_github("liamgilbey/ggwaffle")
      library(ggwaffle)
  • Heatmaps

Comparing Proportions

The following graphs are used to compare proportions:

  • Pie Charts

    • ggpubr package

      View code
      # Pie Charts 
      devtools::install_github("kassambara/ggpubr")
      library(ggpubr)
  • Diverging Bar-graphs

  • Vertical

  • Stacked-densities

  • Mosaic Plots

    • ggmosaic package

      View code
      # Mosaic Charts 
      devtools::install_github("haleyjeppson/ggmosaic")
      library(ggmosaic)
  • Treemaps

    • treemapify package

      View code
      # Treemaps
      devtools::install_github("wilkox/treemapify")
      library(treemapify)

Comparing Distributions

These graphs can be used to compare multiple variable distributions:

  • Overlapping Histograms

  • Overlapping Frequency Polygons

  • Overlapping Dot-Plots

  • Bee-swarm Plots

    • ggbeeswarm package

      View code
      # Bee-swarm Plots
      devtools::install_github("eclarke/ggbeeswarm")
      library(ggbeeswarm)
  • Overlapping Densities

  • Ridgeline Plots

    • ggridges package

      View code
      # Ridgeline plots 
      devtools::install_github("wilkelab/ggridges")
      library(ggridges)
  • Grouped Box-plots

  • Violin plots

  • Rain-cloud plots

    • raincloudplots and ggdist packages

      View code
      # Rain-cloud plots 
      remotes::install_github('jorvlan/raincloudplots')
      remotes::install_github('mjskay/ggdist')
      library(raincloudplots)
      library(ggdist)

Relationships

The following graphs are used to display relationships between two (or more) variables:

  • Scatter plots

  • Grouped scatter plots

  • Bubble charts

  • Grouped bubble charts

  • Alluvial charts

    • ggalluvial package

      View code
      # Alluvial charts
      devtools::install_github("corybrunson/ggalluvial")
      library(ggalluvial)
  • Bump charts

    • ggbump package

      View code
      # Bump charts
      devtools::install_github("davidsjoberg/ggbump")
      library(ggbump)
  • Parallel Sets

    • ggforce package

      View code
      # Bump charts
      devtools::install_github("thomasp85/ggforce")
      library(ggforce)
  • Slope graphs

  • Density Contours

  • 2D Bins

  • Hex Bins

  • Correlograms